package managedbean.CRM.SaleLead;

import entity.CRM.SaleLead;
import java.io.Serializable;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.PhaseEvent;
import session.stateless.CRM.SaleLeadBeanLocal;

@ManagedBean
@ViewScoped

public class EditSaleLeadManagerBean implements Serializable
{
    @EJB
    private SaleLeadBeanLocal saleLeadBeanLocal;
    private SaleLead saleLeadToEdit;
    private String statusMessage;

    
    public SaleLead getSaleLeadToEdit() {
        return saleLeadToEdit;
    }
    public void setSaleLeadToEdit(SaleLead saleLeadToEdit) {
        this.saleLeadToEdit = saleLeadToEdit;
    }

    public String getStatusMessage() {
        return statusMessage;
    }
    public void setStatusMessage(String statusMessage) {
        this.statusMessage = statusMessage;
    }
    
    public EditSaleLeadManagerBean() {}
    
    public void initView(PhaseEvent event){
        if(saleLeadToEdit == null)
        {            
            saleLeadToEdit = (SaleLead)FacesContext.getCurrentInstance().getExternalContext().getFlash().get("selectedSaleLead");            
        }
    }
    
    public void updateExistingSaleLead(ActionEvent event)
    {
        try {
            saleLeadBeanLocal.updateSaleLead(saleLeadToEdit.getRegistrationNumber(), saleLeadToEdit.getSaleLeadName(), saleLeadToEdit.getSaleLeadAddress(), saleLeadToEdit.getCustomerType());
            statusMessage = "Sale Inquiry Updated Successfully";

            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Update Sale Lead Result: " + statusMessage + ")", ""));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
